home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9951 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: EU.net!sun4nl!xs4all!falstaff
  2. From: falstaff@xs4all.nl (Falstaff)
  3. Newsgroups: comp.os.linux.help,comp.lang.c
  4. Subject: Re: strncpy bug?
  5. Date: 14 Mar 1996 09:46:42 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4i8pu2$lq7@news.xs4all.nl>
  8. References: <ccurtis.826776589@ee.fit.edu>
  9. NNTP-Posting-Host: xs1.xs4all.nl
  10. X-Newsreader: NN version 6.5.0 #666 (NOV)
  11.  
  12. ccurtis@ee.fit.edu (Christopher W. Curtis) writes:
  13.  
  14. >Hi.
  15.  
  16. >I was wondering if this is a Linux thing (kernel 1.2.1) or a
  17. >more general 'problem'.  If you call strncpy as such:
  18. >    strncpy( dest, NULL, x );
  19. >it will seg fault.  Is this common among all platforms, or
  20. >just with Linux?
  21.  
  22. >The man page says nothing about it, but I would have presumed
  23. >that if str[n]cpy were passed NULL as a source, it would
  24. >merely catenate the destination.  Did I presume wrong?
  25.  
  26. If the strncpy() manual does not report any special cases, you should
  27. assume that there are none.
  28. For example, free() supports NULL as a special no-op case, but
  29. strncpy() just tries to copy a string from address 0.
  30. As this is generally not correct, Linux will trap accesses to address
  31. 0, so you can immediately see your program has an error.
  32.  
  33. Frank
  34. --
  35. The famous GIICM now on line:  http://www.xs4all.nl/~falstaff/GIICM.html
  36. ------------------------------------------------------------------------
  37. Frank A. Vorstenbosch        +31-(70)-355 5241        falstaff@xs4all.nl
  38.